<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>根据数组将记录插入表中</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.pg-convert.html">pg_convert</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pg-copy-to.html">pg_copy_to</a></div>
 <div class="up"><a href="ref.pgsql.html">PostgreSQL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.pg-copy-from" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">pg_copy_from</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">pg_copy_from</span> &mdash; <span class="dc-title">
     根据数组将记录插入表中
    </span></p>

   </div>
 
 <div class="refsect1 description" id="refsect1-function.pg-copy-from-description">
  <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="type">bool</span> <span class="methodname"><strong>pg_copy_from</strong></span>  
       ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span>  
      , <span class="methodparam"><span class="type">string</span> <code class="parameter">$table_name</code></span>
      , <span class="methodparam"><span class="type">array</span> <code class="parameter">$rows</code></span>
      [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$delimiter</code></span>
      [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$null_as</code></span>
     ]] )</div>

    <p class="para rdfs-comment">
     <span class="function"><strong>pg_copy_from()</strong></span> 将数组 <em><code class="parameter">rows</code></em> 的内容作为记录插入表中。它在内部使用了 <em>COPY FROM</em> SQL 命令来插入记录。
    </p>
   </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-copy-from-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">connection</code></em></dt>

     <dd>

      <p class="para">
       PostgreSQL database connection resource.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">table_name</code></em></dt>

     <dd>

      <p class="para">
       Name of the table into which to copy the <em><code class="parameter">rows</code></em>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">rows</code></em></dt>

     <dd>

      <p class="para">
       An <span class="type"><a href="language.types.array.html" class="type array">array</a></span> of data to be copied into <em><code class="parameter">table_name</code></em>.
       Each value in <em><code class="parameter">rows</code></em> becomes a row in <em><code class="parameter">table_name</code></em>.
       Each value in <em><code class="parameter">rows</code></em> should be a delimited string of the values
       to insert into each field.  Values should be linefeed terminated.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">delimiter</code></em></dt>

     <dd>

      <p class="para">
       The token that separates values for each field in each element of
       <em><code class="parameter">rows</code></em>.  Default is <em>TAB</em>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">null_as</code></em></dt>

     <dd>

      <p class="para">
       How SQL <em>NULL</em> values are represented in the
       <em><code class="parameter">rows</code></em>.  Default is \N (&quot;\N&quot;).
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-copy-from-returnvalues">
  <h3 class="title">返回值</h3>
   <p class="para">
    成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
   </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.pg-copy-from-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2022">
    <p><strong>Example #1 <span class="function"><strong>pg_copy_from()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;$db&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$rows&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_copy_to</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$table_name</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DELETE&nbsp;FROM&nbsp;</span><span style="color: #0000BB">$table_name</span><span style="color: #DD0000">"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">pg_copy_from</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$table_name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$rows</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div> 
  </p>
 </div>

  
 <div class="refsect1 seealso" id="refsect1-function.pg-copy-from-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.pg-copy-to.html" class="function" rel="rdfs-seeAlso">pg_copy_to()</a> - 将一个表拷贝到数组中</span></li>
   </ul>
  </p>
 </div>

  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.pg-convert.html">pg_convert</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pg-copy-to.html">pg_copy_to</a></div>
 <div class="up"><a href="ref.pgsql.html">PostgreSQL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
